#include "Problem18.hpp"

Problem18::Problem18(Index dimension) :
	UnconstrainedProblem(dimension) {
	assert(dimension >= 1);
}

bool Problem18::get_nlp_info(Index& n, Index& nnz_h_lag) {
	n = dimension;
	nnz_h_lag = 0;

	return true;
}

bool Problem18::get_starting_point(Index n, Number* x) {
	for (Index i = 0; i < dimension; ++i) {
		x[i] = 1;
	}

	return true;
}

bool Problem18::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) {
	Number sum = 0;
	for (int i = 0; i < n; i++) {
		sum += (i + 1) * x[i] * x[i];
	}
	obj_value = sum * sum;
	return true;
}

bool Problem18::eval_grad_f(Index n, const Number* x, bool new_x,
		Number* grad_f) {
	Number sum = 0;
	for (int i = 0; i < n; i++) {
		sum += (i + 1) * x[i] * x[i];
	}

	for (int i = 0; i < n; i++) {
		grad_f[i] = 4 * (i + 1) * x[i] * sum;
	}

	return true;
}

void Problem18::newX(const Number* x) {

}

